package ee.fj.utils;

public class SecondsFormatter {
	public static String format(long seconds) {
		if (seconds == 0)
			return formatVal(0, 0, 0, 0);
		long d = 0, h =0 , m = 0, s = 0;
		d = seconds / 86400;
		long remainder = seconds % 86400;
		h = remainder / 3600;
		remainder = remainder % 3600;
		m = remainder / 60;
		s = remainder % 60;
		return formatVal(d, h, m, s);

	}
	private static String formatVal(long d, long h, long m, long s) {
		String retVal = formatVal(m) + ":" + formatVal(s);
		if (d > 0) {
			return d + " " + formatVal(h) + ":" + retVal;
		} else if (h > 0) {
			return formatVal(h) + ":" + retVal;
		}
		return retVal;
	}
	private static String formatVal(long val) {
		return (val < 10 ? "0" : "") + val;
	}
}
